﻿/*
   Author: Tomer Paz
   BOGO.com
   2009
*/

/* Multi-Language handling Singleton */

package monopoly.Localization {
	import flash.system.Capabilities;
	import monopoly.Localization.English;
	import monopoly.Localization.Hebrew;
	import monopoly.Localization.Russian;
	
	public class LocalLanguage implements ILocalLanguage
		{
		private var _myLang:String = "en"; // default to English
		private var _machineLang:String = null;
		private var _workStr:String = null;
		private var _SupportedLanguages:Object;
		
		//singleton
		private static var _instance:LocalLanguage;
				
		public function LocalLanguage(parameter:SingletonEnforcer):void
			{
			}
		// singleton
		public static function getInstance():LocalLanguage
			{
			if (null == _instance)
				{
				_instance = new LocalLanguage(new SingletonEnforcer());
			
				_instance._machineLang = flash.system.Capabilities.language.substr(0, 2);
			
				// supported languages
				_instance._SupportedLanguages = new Object( );
				// attach language class to ISO code
				_instance._SupportedLanguages["en"] = English;
				_instance._SupportedLanguages["il"] = Hebrew;
				_instance._SupportedLanguages["ru"] = Russian;
				//_instance._SupportedLanguages["fr"] = French;
				//_instance._SupportedLanguages["it"] = Italian;
				//... to do...
						
				// set default language
				if (_instance._SupportedLanguages[_instance._machineLang] != undefined)
					_instance._myLang =  _instance._machineLang;
				}
			return _instance;
			}
			
		/* ILocalLanguage implementation */
		
		public function set MyLang(lang:String):void
			{
			if (null != lang)
				{
				if (_instance._SupportedLanguages[lang] != undefined)
					_instance._myLang = lang;
				}
			}
		public function get MyLang():String
			{
			return _instance._myLang;
			}
		
		/* language specific functions */ 
		
		/* general layout text */
		
		public function get GameInfo():String				{ return _instance._SupportedLanguages[_instance._myLang].GameInfo; }
		public function get ActionsHistory():String			{ return _instance._SupportedLanguages[_instance._myLang].ActionsHistory; }
		public function get Chat():String					{ return _instance._SupportedLanguages[_instance._myLang].Chat; }
		// player status
		public function get StatusCash():String				{ return _instance._SupportedLanguages[_instance._myLang].StatusCash; }
		public function get StatusDiesRes():String			{ return _instance._SupportedLanguages[_instance._myLang].StatusDiesRes; }
		public function get StatusEmptySlot():String		{ return _instance._SupportedLanguages[_instance._myLang].StatusEmptySlot; }
		public function     StatusHasQuit(pname:String):String
			{
			_instance._workStr = _instance._SupportedLanguages[_instance._myLang].StatusHasQuit;
			return _instance._workStr.replace("%s", pname);
			}
		public function     StatusCCash(pname:String, pcash:int):String
			{
			_instance._workStr = _instance._SupportedLanguages[_instance._myLang].StatusCCash;
			_instance._workStr = _instance._workStr.replace("%s", pname);
			return _instance._workStr.replace("%d", String(pcash));
			}
		
		/* popup msgs*/
		
		public function get MsgJReady():String				{ return _instance._SupportedLanguages[_instance._myLang].MsgJReady; }
		public function get MsgJText():String				{ return _instance._SupportedLanguages[_instance._myLang].MsgJText; }
		public function get MsgJSReady():String				{ return _instance._SupportedLanguages[_instance._myLang].MsgJSReady; }
		public function get MsgJSText():String				{ return _instance._SupportedLanguages[_instance._myLang].MsgJSText; }
		public function get MsgJoinWait():String 			{ return _instance._SupportedLanguages[_instance._myLang].MsgJoinWait; }
		public function MsgJSWaitPlayer(pname:String):String
			{
			_instance._workStr = _instance._SupportedLanguages[_instance._myLang].MsgJSWaitPlayer;
			return _instance._workStr.replace("%s", pname);
			}
		// bank messages
		public function get MsgBankApproveReq():String		{ return _instance._SupportedLanguages[_instance._myLang].MsgBankApproveReq; }
		public function     MsgBankBuyProperty(prname:String, fcost:int):String
			{
			_instance._workStr = _instance._SupportedLanguages[_instance._myLang].MsgBankBuyProperty;
			return _instance._workStr.replace("%s", prname).replace("%d", String(fcost));
			}
		// waiting server message
		public function get MsgWaitServer():String			{ return _instance._SupportedLanguages[_instance._myLang].MsgWaitServer; }
		// 6xx messages and Server response messages
		public function get MsgAcceptRejectTitle():String	{ return _instance._SupportedLanguages[_instance._myLang].MsgAcceptRejectTitle; }
		public function get MsgAccept():String 				{ return _instance._SupportedLanguages[_instance._myLang].MsgAccept; }
		public function get MsgReject():String				{ return _instance._SupportedLanguages[_instance._myLang].MsgReject; }
		public function get MsgReqSuccess():String			{ return _instance._SupportedLanguages[_instance._myLang].MsgReqSuccess; }
		public function get MsgResReply():String			{ return _instance._SupportedLanguages[_instance._myLang].MsgResReply; }
		// auction messages
		public function     MsgAucIOffer(sum:int):String
			{
			_instance._workStr = _instance._SupportedLanguages[_instance._myLang].MsgAucIOffer;
			return _instance._workStr.replace("%d", String(sum));
			}
		public function get MsgAucPlayersOffer():String 	{ return _instance._SupportedLanguages[_instance._myLang].MsgAucPlayersOffer; }
		public function     MsgAucPlayerPass(pname:String):String
			{
			_instance._workStr = _instance._SupportedLanguages[_instance._myLang].MsgAucPlayerPass;
			return _instance._workStr.replace("%s", pname);
			}
		public function     MsgAucPlayerOffer(pname:String, sum:int):String
			{
			_instance._workStr = _instance._SupportedLanguages[_instance._myLang].MsgAucPlayerOffer;
			return _instance._workStr.replace("%s", pname).replace("%d", String(sum));
			}
		public function get MsgAucEveryonePass():String 	{ return _instance._SupportedLanguages[_instance._myLang].MsgAucEveryonePass; }
		public function     MsgAucSuccess(plname:String, prname:String, sum:int):String
			{
			_instance._workStr = _instance._SupportedLanguages[_instance._myLang].MsgAucSuccess;
			
			var pattern:RegExp = /%s/;
			_instance._workStr = _instance._workStr.replace(pattern, plname);
			_instance._workStr = _instance._workStr.replace(pattern, prname);
			
			return _instance._workStr.replace("%d", sum);
			}
		// upgrade messages
		public function get MsgUpgMaxLevel():String			{ return _instance._SupportedLanguages[_instance._myLang].MsgUpgMaxLevel; }
		public function get MsgUpgNoCash():String			{ return _instance._SupportedLanguages[_instance._myLang].MsgUpgNoCash; }
		public function get MsgUpgError():String			{ return _instance._SupportedLanguages[_instance._myLang].MsgUpgError; }
		public function get MsgUpgUprading():String			{ return _instance._SupportedLanguages[_instance._myLang].MsgUpgUprading; }
		public function get MsgUpgSuccess():String			{ return _instance._SupportedLanguages[_instance._myLang].MsgUpgSuccess; }
		// pay/buy messages
		public function     MsgPayOwner(fee:int, pname:String):String
			{
			_instance._workStr = _instance._SupportedLanguages[_instance._myLang].MsgPayOwner;
			return _instance._workStr.replace("%d", String(fee)).replace("%s", pname);
			}
		public function get MsgPurchaseSuccess():String		{ return _instance._SupportedLanguages[_instance._myLang].MsgPurchaseSuccess; }
		public function get MsgBuyReject():String			{ return _instance._SupportedLanguages[_instance._myLang].MsgBuyReject; }
		public function     MsgBuyOffer(plname:String, prname:String):String
			{
			_instance._workStr = _instance._SupportedLanguages[_instance._myLang].MsgBuyOffer;
			
			var pattern:RegExp = /%s/;
			_instance._workStr = _instance._workStr.replace(pattern, plname);
			return _instance._workStr.replace(pattern, prname);
			}
		// sell messages
		public function get MsgSellReject():String			{ return _instance._SupportedLanguages[_instance._myLang].MsgSellReject; }
		public function     MsgSellWait(pname:String):String
			{
			_instance._workStr = _instance._SupportedLanguages[_instance._myLang].MsgSellWait;
			return _instance._workStr.replace("%s", pname);
			}
		public function     MsgSellOffer(plname:String, prname:String):String
			{
			_instance._workStr = _instance._SupportedLanguages[_instance._myLang].MsgSellOffer;
			var pattern:RegExp = /%s/;
			_instance._workStr = _instance._workStr.replace(pattern, plname);
			return _instance._workStr.replace(pattern, prname);
			}
		public function     MsgSellIOffer(prname:String, plname:String, fcost:int):String
			{
			_instance._workStr = _instance._SupportedLanguages[_instance._myLang].MsgSellIOffer;
			var pattern:RegExp = /%s/;
			_instance._workStr = _instance._workStr.replace(pattern, prname);
			_instance._workStr = _instance._workStr.replace(pattern, plname);
			return _instance._workStr.replace("%d", String(fcost));
			}
		// exchange messages
		public function get MsgExchangeReject():String		{ return _instance._SupportedLanguages[_instance._myLang].MsgExchangeReject; }
		public function     MsgExchangeOffer(plname:String, prname:String):String
			{
			_instance._workStr = _instance._SupportedLanguages[_instance._myLang].MsgExchangeOffer;
			var pattern:RegExp = /%s/;
			_instance._workStr = _instance._workStr.replace(pattern, plname);
			return _instance._workStr.replace(pattern, prname);
			}
		// partner messages
		public function get MsgPartnerReject():String		{ return _instance._SupportedLanguages[_instance._myLang].MsgPartnerReject; }
		
		// end turn
		public function get MsgEndTurnTitle():String		{ return _instance._SupportedLanguages[_instance._myLang].MsgEndTurnTitle; }
		public function get MsgEndTurnText():String			{ return _instance._SupportedLanguages[_instance._myLang].MsgEndTurnText; }
		// game over, quit, resign
		public function get MsgGameOver():String			{ return _instance._SupportedLanguages[_instance._myLang].MsgGameOver; }
		// end game (resign)
		public function get MsgResignLabel():String			{ return _instance._SupportedLanguages[_instance._myLang].MsgResignLabel; }
		public function get MsgResignTitle():String			{ return _instance._SupportedLanguages[_instance._myLang].MsgResignTitle; }
		public function get MsgResignText():String			{ return _instance._SupportedLanguages[_instance._myLang].MsgResignText; }
		public function get MsgResignYes():String			{ return _instance._SupportedLanguages[_instance._myLang].MsgResignYes; }
		public function get MsgResignNo():String			{ return _instance._SupportedLanguages[_instance._myLang].MsgResignNo; }
		
		/* dialogs */
		
		public function get DlgRadioDone():String			{ return _instance._SupportedLanguages[_instance._myLang].DlgRadioDone; }
		
		// auction dialog
		public function     DlgAucLabelMOffer(prname:String, sum:int):String
			{
			_instance._workStr = _instance._SupportedLanguages[_instance._myLang].DlgAucLabelMOffer;
			_instance._workStr = _instance._workStr.replace("%s", prname);
			return _instance._workStr.replace("%d", String(sum));
			}
		public function     DlgAucLabelNOffer(prname:String, sum:int):String
			{
			_instance._workStr = _instance._SupportedLanguages[_instance._myLang].DlgAucLabelNOffer;
			_instance._workStr = _instance._workStr.replace("%s", prname);
			return _instance._workStr.replace("%d", String(sum));
			}
		// bank dialog
		public function get DlgBankLabel():String			{ return _instance._SupportedLanguages[_instance._myLang].DlgBankLabel; }
		public function     DlgBankText(fcost:int, myCash:int):String
			{
			_instance._workStr = _instance._SupportedLanguages[_instance._myLang].DlgBankText;
			var pattern:RegExp = /%d/;
			_instance._workStr = _instance._workStr.replace(pattern, String(fcost));
			return _instance._workStr.replace(pattern, String(myCash));
			}
		public function get DlgBankBuy():String				{ return _instance._SupportedLanguages[_instance._myLang].DlgBankBuy; }
		public function get DlgBankPass():String			{ return _instance._SupportedLanguages[_instance._myLang].DlgBankPass; }
		public function get DlgBankShort():String			{ return _instance._SupportedLanguages[_instance._myLang].DlgBankShort; }
		// join/view/start dialog
		public function get DlgJVSJoin():String				{ return _instance._SupportedLanguages[_instance._myLang].DlgJVSJoin; }
		public function get DlgJVSStart():String			{ return _instance._SupportedLanguages[_instance._myLang].DlgJVSStart; }
		public function get DlgJVSView():String				{ return _instance._SupportedLanguages[_instance._myLang].DlgJVSView; }
		// mortgage dialog
		public function get DlgMortgageLabel():String		{ return _instance._SupportedLanguages[_instance._myLang].DlgMortgageLabel; }
		public function     DlgMortgageText(owed:int):String
			{
			_instance._workStr = _instance._SupportedLanguages[_instance._myLang].DlgMortgageText;
			return _instance._workStr.replace("%d", String(owed));
			}
		public function     DlgMortgageUpd(owed:int, sum:int):String
			{
			_instance._workStr = _instance._SupportedLanguages[_instance._myLang].DlgMortgageUpd;
			var pattern:RegExp = /%d/;
			_instance._workStr = _instance._workStr.replace(pattern, String(owed));
			return _instance._workStr.replace(pattern, String(sum));
			}
		// play dialog
		public function get DlgPlayDiesOption():String		{ return _instance._SupportedLanguages[_instance._myLang].DlgPlayDiesOption; }
		public function get DlgPlayActionOption():String	{ return _instance._SupportedLanguages[_instance._myLang].DlgPlayActionOption; }
		public function get DlgPlayLabel():String			{ return _instance._SupportedLanguages[_instance._myLang].DlgPlayLabel; }
		public function get DlgPlayText():String			{ return _instance._SupportedLanguages[_instance._myLang].DlgPlayText; }
		// player negotiate dialog
		public function get DlgNegPartnerOption():String	{ return _instance._SupportedLanguages[_instance._myLang].DlgNegPartnerOption; }
		public function get DlgNegExchangeOption():String	{ return _instance._SupportedLanguages[_instance._myLang].DlgNegExchangeOption; }
		public function get DlgNegBuyOption():String		{ return _instance._SupportedLanguages[_instance._myLang].DlgNegBuyOption; }
		public function get DlgNegPassOption():String		{ return _instance._SupportedLanguages[_instance._myLang].DlgNegPassOption; }
		public function     DlgNegText(pname:String, pcash:int):String
			{
			var pattern:RegExp = /%s/g;
			_instance._workStr = _instance._SupportedLanguages[_instance._myLang].DlgNegText;
			_instance._workStr = _instance._workStr.replace(pattern, pname);
			return _instance._workStr.replace("%d", String(pcash));
			}
		public function get DlgNegLabel():String			{ return _instance._SupportedLanguages[_instance._myLang].DlgNegLabel; }
		// pre-dies dialog
		public function get DlgPreDiesSellOption():String	{ return _instance._SupportedLanguages[_instance._myLang].DlgPreDiesSellOption; }
		public function get DlgPreDiesAucOption():String	{ return _instance._SupportedLanguages[_instance._myLang].DlgPreDiesAucOption; }
		public function get DlgPreDiesMortOption():String	{ return _instance._SupportedLanguages[_instance._myLang].DlgPreDiesMortOption; }
		public function get DlgPreDiesUpgrade():String		{ return _instance._SupportedLanguages[_instance._myLang].DlgPreDiesUpgrade; }
		public function get DlgPreDiesReturn():String		{ return _instance._SupportedLanguages[_instance._myLang].DlgPreDiesReturn; }
		public function get DlgPreDiesLabel():String		{ return _instance._SupportedLanguages[_instance._myLang].DlgPreDiesLabel; }
		public function get DlgPreDiesText():String			{ return _instance._SupportedLanguages[_instance._myLang].DlgPreDiesText; }
		// sell dialog
		public function     DlgSellText(prname:String, fcost:int):String
			{
			_instance._workStr = _instance._SupportedLanguages[_instance._myLang].DlgSellText;
			_instance._workStr = _instance._workStr.replace("%s", prname);
			return _instance._workStr.replace("%d", String(fcost));
			}
		
		public function get DlgSellPOption():String			{ return _instance._SupportedLanguages[_instance._myLang].DlgSellPOption; }
		// upgrade dialog
		public function get DlgUpgradeLabel():String		{ return _instance._SupportedLanguages[_instance._myLang].DlgUpgradeLabel; }
		public function     DlgUpgradeLevel(level:int, cost:int):String
			{
			_instance._workStr = _instance._SupportedLanguages[_instance._myLang].DlgUpgradeLevel;
			var pattern:RegExp = /%d/;
			_instance._workStr = _instance._workStr.replace(pattern, String(level));
			return _instance._workStr.replace(pattern, String(cost));
			}
		public function get DlgUpgradePass():String			{ return _instance._SupportedLanguages[_instance._myLang].DlgUpgradePass; }
		public function     DlgUpgradeText(pname:String):String
			{
			_instance._workStr = _instance._SupportedLanguages[_instance._myLang].DlgUpgradeText;
			return _instance._workStr.replace("%s", pname);
			}
		}
}
class SingletonEnforcer {}
